/*!
 * \file FileProcessing.h
 * \brief There are functions related with building tree of regular expression and generate string.
 */

#include <vector>
#include <string>
#include "Node_operation.h"
#include "Node_CharacterClass.h"
#include "Node.h"

using namespace std;

/*!
 * \brief Opens input file, reads info, uses this info for building tree of regular expression.
 * \param[in] filename Path to input file.
 * \return Tree of regular expression.
 */
const Node * FileProcessing(char * filename);

/*!
 * \brief Separates input string to lexems.
 * \param[in] Data contains data from input file.
 * \return Vector of lexems.
 */
const vector<string> GenerateLexems(const string &data);

/*!
 * \brief Checking lexem for errors.
 * \param[in] Lexem generated lexem.
 */
void CheckLexem(const string &lexem);

/*!
 * \brief Builds program tree from lexems.
 * \param[in] Lexems regular expression in reverse polish notation.
 * \return Tree of regular expression.
 */
Node * GenerateTree(const  vector<string> &lexems);

/*!
 * \brief Attaches operand(s) to operation.
 * \param[in, out] oper Regex's operation.
 * \param[in, out] riter Reverse iterator of lexems' vector.
 * \param[in] rend Reverse iterator of lexems' vector, which points to end.
 */
void ChainOperands(Node_operation * oper, vector<string>::const_reverse_iterator& riter, vector<string>::const_reverse_iterator& rend);

/*!
 * \brief Generates a string of minimum length on the basis of the parse tree of the regular expression.
 * \param[in] node Program tree of regular expression.
 */
string GenerateString (Node* node);

bool CmpCharClass(const Node_CharacterClass & n1, const Node_CharacterClass & n2);
bool CmpCharClass(const string & currChar, const Node_CharacterClass & n1);
bool CmpNodes (const Node & n1, const Node & n2);